"""异常类定义"""


class APIError(Exception):
    """API调用基础异常"""
    
    def __init__(self, message, code=None, response=None):
        self.message = message
        self.code = code
        self.response = response
        super().__init__(f"API错误: {message} (错误码: {code})")


class AuthenticationError(APIError):
    """认证错误"""
    
    def __init__(self, message="认证失败", code=401, response=None):
        super().__init__(message, code, response)


class RequestError(APIError):
    """请求错误"""
    
    def __init__(self, message="请求失败", code=None, response=None):
        super().__init__(message, code, response)


class RateLimitError(APIError):
    """请求频率限制错误"""
    
    def __init__(self, message="请求频率过高", code=429, response=None):
        super().__init__(message, code, response)


class ValidationError(APIError):
    """参数验证错误"""
    
    def __init__(self, message="参数验证失败", code=400, response=None):
        super().__init__(message, code, response)